<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateOrdersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('orders', function (Blueprint $table) {
            $table->bigIncrements('id')->comment('订单ID');
            $table->string('order_number', 30)->collate('utf8mb4_unicode_ci')->unique()->comment('订单编号');
            $table->unsignedBigInteger('wechat_user_id')->comment('微信用户ID');
            $table->string('receiver_name', 20)->collate('utf8mb4_unicode_ci')->comment('收货人姓名');
            $table->string('receiver_phone', 20)->collate('utf8mb4_unicode_ci')->comment('联系电话');
            $table->string('shipping_address', 100)->collate('utf8mb4_unicode_ci')->comment('收货地址');
            $table->tinyInteger('status')->default(0)->comment('订单状态：0=待发货，1=已发货，2=已完成，3=已取消');
            $table->string('logistics_company', 50)->collate('utf8mb4_unicode_ci')->nullable()->comment('物流公司名称');
            $table->string('tracking_number', 50)->collate('utf8mb4_unicode_ci')->nullable()->comment('物流单号');
            $table->timestamp('shipped_at')->nullable()->comment('发货时间');
            $table->timestamp('completed_at')->nullable()->comment('完成时间');
            $table->timestamps();

            $table->foreign('wechat_user_id')->references('id')->on('wechat_users');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('orders');
    }
}